package com.yidu.ruifeng_logistics.service.impl;

import com.yidu.ruifeng_logistics.entity.LogisticsModel;
import com.yidu.ruifeng_logistics.dao.LogisticsModelDao;
import com.yidu.ruifeng_logistics.service.LogisticsModelService;
import com.yidu.ruifeng_logistics.vo.LogisticsModelFllVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (LogisticsModel)表服务实现类
 *
 * @author 张皓超
 * @since 2021-03-09 14:24:40
 */
@Service("logisticsModelService")
public class LogisticsModelServiceImpl implements LogisticsModelService  {


    Logger logger = LoggerFactory.getLogger(this.getClass());


    @Resource
    private LogisticsModelDao logisticsModelDao;

    /**
     * 通过ID查询单条数据
     *
     * @param modelId 主键
     * @return 实例对象
     */
    @Override
    public LogisticsModel queryById(Integer modelId) {
        return this.logisticsModelDao.queryById(modelId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<LogisticsModel> queryAllByLimit(int offset, int limit) {
        return this.logisticsModelDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param logisticsModel 实例对象
     * @return 实例对象
     */
    @Override
    public LogisticsModel insert(LogisticsModel logisticsModel) {
        this.logisticsModelDao.insert(logisticsModel);
        return logisticsModel;
    }

    /**
     * 修改数据
     *
     * @param logisticsModel 实例对象
     * @return 实例对象
     */
    @Override
    public LogisticsModel update(LogisticsModel logisticsModel) {
        this.logisticsModelDao.update(logisticsModel);
        return this.queryById(logisticsModel.getModelId());
    }

    /**
     * 通过主键删除数据
     *
     * @param modelId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer modelId) {
        return this.logisticsModelDao.deleteById(modelId) > 0;
    }

    @Override
    public List<LogisticsModel> queryAll(LogisticsModel logisticsModel) {
        return this.logisticsModelDao.queryAll(logisticsModel);
    }

    @Override
    public List<LogisticsModel> selectI(Integer modelId) {
        return this.logisticsModelDao.selectI(modelId);
    }

    @Override
    public String selectName(Integer modelId) {
        return this.logisticsModelDao.selectName(modelId);
    }

    @Override
    public List<LogisticsModelFllVo> selectReturnVo(LogisticsModel logisticsModel) {
        return this.logisticsModelDao.selectReturnVo(logisticsModel);
    }

    @Override
    public List<LogisticsModel> selectParentIsNull() {
        return this.logisticsModelDao.selectParentIsNull();
    }

    @Override
    public List<LogisticsModel> selectII(Integer modelId) {
        return this.logisticsModelDao.selectII(modelId);
    }

    @Override
    public List<LogisticsModel> queryClient(String modelRemark) {
        return this.logisticsModelDao.queryClient(modelRemark);
    }

    @Override
    public List<LogisticsModel> selectParent(Integer modelId) {
        return this.logisticsModelDao.selectParent(modelId);
    }

    /**
     * 增加修改
     * @param modelId
     * @param modelName
     * @param modelRemark
     * @param modelUrl
     * @param tree
     * @return
     */
    @Override
    public int addAndUpdate(Integer modelId,
                            String modelName,
                            String modelRemark,
                            String modelUrl,
                            Integer tree) {
        int rows=0;
        LogisticsModel logisticsModel=new LogisticsModel();
        logger.info(modelId+":id  name："+modelName+"   备注："+modelRemark+"   url:"+modelUrl+"    上级："+tree);
        logisticsModel.setModelId(modelId);
        logisticsModel.setModelName(modelName);
        logisticsModel.setModelRemark(modelRemark);
        logisticsModel.setModelUrl(modelUrl);
        logisticsModel.setModelParent(tree);

        if (logisticsModel.getModelId()!=null&&logisticsModel.getModelId()!=0){
            rows = logisticsModelDao.update(logisticsModel);
            //修改
        }else{
            rows = logisticsModelDao.insert(logisticsModel);
            //增加
        }
        return rows;
    }

    @Override
    public int selectModelParentIsNull(Integer modelId) {
        return this.logisticsModelDao.selectModelParentIsNull(modelId);
    }

    @Override
    public List<LogisticsModel> selectParentIsNoNull() {
        return this.logisticsModelDao.selectParentIsNoNull();
    }

    @Override
    public List<LogisticsModel> selectModelIdAndParentIsNoNull(Integer modelId) {
        return this.logisticsModelDao.selectModelIdAndParentIsNoNull(modelId);
    }

}
